package net.lzzy.basketballrestful2.controller;

import net.lzzy.basketballrestful2.entity.Basketball;
import org.springframework.web.bind.annotation.*;
import java.util.*;

@RestController
@RequestMapping(value = "/basketballs")
public class BasketballController {

    static Map<Long, Basketball> basketballMap = Collections.synchronizedMap(new HashMap<Long, Basketball>());

    @GetMapping("/")
    public List<Basketball> getBasketballList() {
        List<Basketball> basketballList = new ArrayList<Basketball>(basketballMap.values());
        return basketballList;
    }

    @PostMapping("/")
    public Basketball PostBasketball (@RequestBody Basketball basketball) {
        basketballMap.put(basketball.getId(),basketball);
        return basketball;
    }

    @GetMapping("/{id}")
    public Basketball GetBasketball(@PathVariable Long id) {
        return basketballMap.get(id);
    }

    @PutMapping("/{id}")
    public Basketball PutBasketball(@PathVariable Long id , @RequestBody Basketball basketball) {
        return basketballMap.put(id, basketball);
    }

    @DeleteMapping("/{id}")
    public String deleteBasketball(@PathVariable Long id) {
        basketballMap.remove(id);
        return "删除某个篮球" + id.toString();
    }

}
